Skip to content

Fix FPU register save and restore instructions - #143

Merged
wojciechozga merged 1 commit into
IBM:mainfrom
whensun:fix/fpu-context-save-restore
Oct 23, 2026
Merged

wojciechozga merged 1 commit into
IBM:mainfrom
whensun:fix/fpu-context-save-restore

Conversation

@whensun

@whensun whensun commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Description of the changes

This PR fixes incorrect floating-point register save and restore instructions during heavy context switches.

Previously, save_in_main_memory() used fld, which loads values from memory into floating-point registers. Similarly, restore_from_main_memory() used fsd, which stores floating-point registers into memory.

These operations were reversed and could cause incorrect preservation of f0–f31 across context switches between the hypervisor and confidential VMs.

This PR corrects the instructions:

  • save_in_main_memory() now uses fsd to save f0–f31 into memory.
  • restore_from_main_memory() now uses fld to restore f0–f31 from memory.

No other functionality is changed.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Formal verification
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactorization (non-breaking change which improves code quality)

How to test this PR?

  1. Build and run ACE-RISCV with the floating-point extension enabled.
  2. Launch a confidential VM and initialize f0–f31 with known values.
  3. Trigger a heavy context switch from VS to HS and back to VS.
  4. Verify that all floating-point registers retain their original values.
  5. Repeat with different register values across confidential VM context switches.

Static inspection confirms that the updated save and restore functions use the correct instructions for all 32 floating-point registers.

The patch also passes git diff --check.

Signed-off-by: whensun <theodoruswensanfebruanto025@gmail.com>
@wojciechozga

Copy link
Copy Markdown
Member

Thank you for this PR. LGTM

@wojciechozga
wojciechozga merged commit 23d9818 into IBM:main Oct 23, 2026
3 checks passed
skehrli added a commit that referenced this pull request Nov 17, 2026
* Add OOPSLA paper, update dependencies (#126)

Signed-off-by: Wojciech Ozga <woz@zurich.ibm.com>

* Crypto dependency updates (#132)

* update crypto dependencies to get rid of generic-array, use sha3-0.11 and upgrade ml-kem

* formatting

Signed-off-by: Wojciech Ozga <woz@zurich.ibm.com>

* update bindgen to 0.73, spin to 0.12, clap to 4.6

* update rand to 0.9 and generate random symmetric key and nonce in TAP serializer

* update rand crate dependency to 0.10

Signed-off-by: Wojciech Ozga <woz@zurich.ibm.com>

* Update AES GCM to 0.11.1

Signed-off-by: Wojciech Ozga <woz@zurich.ibm.com>

---------

Signed-off-by: Wojciech Ozga <woz@zurich.ibm.com>

* Compliance with CodeQL (#139)

* make codebase comliant with CodeQL scans
* update and reduce dependencies
* Fix Github CI

---------

Signed-off-by: Wojciech Ozga <woz@zurich.ibm.com>

* Fix FPU register save and restore instructions (#143)

Signed-off-by: whensun <theodoruswensanfebruanto025@gmail.com>

* Preallocate vector in copy_from_non_confidential_memory (#142)

Signed-off-by: Wojciech Ozga <woz@zurich.ibm.com>

* Fix attestation secret release, key naming, and tests (#144)

Signed-off-by: Wojciech Ozga <woz@zurich.ibm.com>

* Increase ACE OpenSBI hart stack size to 16 KiB (#146)

Signed-off-by: whensun <theodoruswensanfebruanto025@gmail.com>

* fix: bump ocaml compiler in CI

Signed-off-by: Sascha Kehrli <sascha.kehrli@gmail.com>

* fix: disable opam sandboxing in verification CI

Signed-off-by: Sascha Kehrli <sascha.kehrli@gmail.com>

* fix: enforce single-job Rocq compilation in CI

Signed-off-by: Sascha Kehrli <sascha.kehrli@gmail.com>

* bump: refinedrust and matching rust toolchain

Signed-off-by: Sascha Kehrli <sascha.kehrli@gmail.com>

---------

Signed-off-by: Wojciech Ozga <woz@zurich.ibm.com>
Signed-off-by: whensun <theodoruswensanfebruanto025@gmail.com>
Signed-off-by: Sascha Kehrli <sascha.kehrli@gmail.com>
Co-authored-by: Wojciech Ozga <woz@zurich.ibm.com>
Co-authored-by: Whensun <143617993+whensun@users.noreply.github.com>
wojciechozga added a commit that referenced this pull request Nov 18, 2026
* Bump: RefinedRust

* fix

* update dev instructions for compat with current toolchains

* fix: add missing rr::skip annotations

* ci: allow 0 pruned modules

* bump: refinedrust

* bump: rust toolchain and RefinedRust

* bump(wip): refinedrust

* wip: fix

* fix: try_write

* bump: refinedrust

* bump: refinedrust

* fix: merge

* bump: toolchain

* bump: refinedrust

* fix: proofs

* fix: adapt to new panic handling

* bump: refinedrust

* bump: refinedrust

* bump refinedrust

* bump: refinedrust

* merge main, bump refinedrust

* Add OOPSLA paper, update dependencies (#126)

Signed-off-by: Wojciech Ozga <woz@zurich.ibm.com>

* Crypto dependency updates (#132)

* update crypto dependencies to get rid of generic-array, use sha3-0.11 and upgrade ml-kem

* formatting

Signed-off-by: Wojciech Ozga <woz@zurich.ibm.com>

* update bindgen to 0.73, spin to 0.12, clap to 4.6

* update rand to 0.9 and generate random symmetric key and nonce in TAP serializer

* update rand crate dependency to 0.10

Signed-off-by: Wojciech Ozga <woz@zurich.ibm.com>

* Update AES GCM to 0.11.1

Signed-off-by: Wojciech Ozga <woz@zurich.ibm.com>

---------

Signed-off-by: Wojciech Ozga <woz@zurich.ibm.com>

* Compliance with CodeQL (#139)

* make codebase comliant with CodeQL scans
* update and reduce dependencies
* Fix Github CI

---------

Signed-off-by: Wojciech Ozga <woz@zurich.ibm.com>

* Fix FPU register save and restore instructions (#143)

Signed-off-by: whensun <theodoruswensanfebruanto025@gmail.com>

* Preallocate vector in copy_from_non_confidential_memory (#142)

Signed-off-by: Wojciech Ozga <woz@zurich.ibm.com>

* Fix attestation secret release, key naming, and tests (#144)

Signed-off-by: Wojciech Ozga <woz@zurich.ibm.com>

* Increase ACE OpenSBI hart stack size to 16 KiB (#146)

Signed-off-by: whensun <theodoruswensanfebruanto025@gmail.com>

* fix: bump ocaml compiler in CI

Signed-off-by: Sascha Kehrli <sascha.kehrli@gmail.com>

* fix: disable opam sandboxing in verification CI

Signed-off-by: Sascha Kehrli <sascha.kehrli@gmail.com>

* fix: enforce single-job Rocq compilation in CI

Signed-off-by: Sascha Kehrli <sascha.kehrli@gmail.com>

* bump: refinedrust and matching rust toolchain

Signed-off-by: Sascha Kehrli <sascha.kehrli@gmail.com>

---------

Signed-off-by: Wojciech Ozga <woz@zurich.ibm.com>
Signed-off-by: whensun <theodoruswensanfebruanto025@gmail.com>
Signed-off-by: Sascha Kehrli <sascha.kehrli@gmail.com>
Co-authored-by: Wojciech Ozga <woz@zurich.ibm.com>
Co-authored-by: Whensun <143617993+whensun@users.noreply.github.com>

* fix: explicitly enable H extension for security monitor builds

Signed-off-by: Sascha Kehrli <sascha.kehrli@gmail.com>

---------

Signed-off-by: Wojciech Ozga <woz@zurich.ibm.com>
Signed-off-by: whensun <theodoruswensanfebruanto025@gmail.com>
Signed-off-by: Sascha Kehrli <sascha.kehrli@gmail.com>
Co-authored-by: Lennard Gäher <l.gaeher@posteo.de>
Co-authored-by: Wojciech Ozga <woz@zurich.ibm.com>
Co-authored-by: Whensun <143617993+whensun@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants